﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace EDMS.Admin.Notice
{
    public partial class UpdateNotice : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initNotice();
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            updateNotice();
        }

        protected void btnEsc_Click(object sender, EventArgs e)
        {
            Response.Redirect("NoticeInfo.aspx");
        }

        //信息初始化
        void initNotice()
        {
            using (DataClassesDataContext dc = new DataClassesDataContext())
            {
                var gg = from s in dc.Xjgg
                         where s.ggbh == Convert.ToInt32(Request.QueryString["GID"])
                         select new
                         {
                             bh = s.ggbh,
                             bt = s.ggbt,
                             nr = s.nr,
                             sj = s.fbsj,
                             fbr = s.fbr,
                             bj = s.flag
                         };
                foreach (var i in gg)
                {
                    txtGgbt.Text = i.bt;
                    txtGgnr.Text = i.nr;
                    txtFbr.Text = i.fbr;
                    deFbsj.Value = i.sj;
                    CmbBj.Value = i.bj;
                }
            }
        }
        //更新
        void updateNotice()
        {
            using (DataClassesDataContext dc = new DataClassesDataContext())
            {
                var gg = dc.Xjgg.Select(s => s)
                   .Where(s => s.ggbh == Convert.ToInt32(Request.QueryString["GID"]))
                   .SingleOrDefault();
                gg.ggbt = txtGgbt.Text;
                gg.nr = txtGgnr.Text;
                gg.fbr = txtFbr.Text;
                gg.fbsj = Convert.ToDateTime(deFbsj.Text);
                gg.flag = CmbBj.Value.ToString();
                dc.SubmitChanges();
                Frame.Global.GlobalFunctions.Alert("选举公告修改成功！");
            }
        }
    }
}